package com.hyt.it.ogt.kq.service.gov.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.hyt.core.base.BaseServiceImpl;
import com.hyt.it.ogt.kq.service.gov.mapper.CandidatePhotoMapper;
import com.hyt.it.ogt.kq.service.model.entity.CandidatePhoto;
import com.hyt.it.ogt.kq.service.gov.service.ICandidatePhotoService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 考生照片表 服务实现类
 * </p>
 *
 * @author huangyh
 * @since 2021-03-08
 */
@Service
public class CandidatePhotoServiceImpl extends BaseServiceImpl<CandidatePhotoMapper, CandidatePhoto> implements ICandidatePhotoService {

    @Override
    public void deleteCandidatePhotos(String taskId, List<String> candidateIdList) {
        QueryWrapper<CandidatePhoto> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda()
                .eq(CandidatePhoto::getTaskId, taskId)
                .in(CollectionUtils.isNotEmpty(candidateIdList), CandidatePhoto::getCandidateId, candidateIdList)
                .eq(CandidatePhoto::getDelFlag, false);
        this.remove(queryWrapper);
        //获取需删除的考生照片数据
//        List<CandidatePhoto> candidatePhotoList = candidatePhotoMapper.getByCandidateIds(candidateIds);
//        List<String> photoIdList = candidatePhotoList.stream()
//                .map(CandidatePhoto::getId)
//                .collect(Collectors.toList());
//        //删除考生照片表数据
//        removeByIds(photoIdList);
//        //删除文件服务器上的考生照片文件
//        //: 后续需改为华为云OBS上删除文件
//        candidatePhotoList.forEach(photo -> fileClient.deleteFile(photo.getPhotoPath()));
    }

    @Override
    public List<CandidatePhoto> listByTaskId(String taskId) {
        QueryWrapper<CandidatePhoto> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda()
                .eq(CandidatePhoto::getTaskId, taskId)
                .eq(CandidatePhoto::getDelFlag, false);
        return list(queryWrapper);
    }

}
